package com.codeduck.config;

import com.codeduck.utils.SpringBeanUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;
import org.springframework.jdbc.datasource.lookup.JndiDataSourceLookup;

import javax.sql.DataSource;

/**
 * @author: <a href="mailto:codeduck@163.com">code-duck</a>
 * @date: 2025/7/30
 */
@Configuration
@DependsOn({"tomcatConfig"})
public class DataSourceConfig {
    @Value("${spring.datasource.jndi-name}")
    private String jndiName;
    private final JndiDataSourceLookup jndiDataSourceLookup = new JndiDataSourceLookup();

    @Bean(name = "masterDataSource")
    public DataSource dataSource() {
        return jndiDataSourceLookup.getDataSource(jndiName);
    }
}
